class Users {
    select(req, res) {
        req.db.query('select `id`,`username`,`age` from `users`', (error, result) => {
            res.send(result);
        })
    }
    add(req, res) {
        let username = req.body.username, age = req.body.age;
        req.db.query('insert into `users` set `username`="' + username + '",`age`="' + age + '"', (error, result) => {
            res.send(result);
        });
    }
    update(req, res) {
        let id = req.query.id
        req.db.query('update `users` set `username`="yangliu" where `id`="' + id + '"', (error, result) => {
            res.send(result)
        })
    }
    del(req, res) {
        let id = req.query.id
        req.db.query('delete from `users` where `id`="' + id + '"', (error, result) => {
            res.send(result)
        })
    }
    // 编辑
    find(req, res) {
        let id = req.query.id
        req.db.query('select `id`,`username`,`age` from `users` where `id`="' + id + '"', (error, result) => {
            res.send(result[0])
        })
    }
    edit(req, res) {
        let username = req.body.username,
            age = req.body.age,
            id = req.body.id;
        req.db.query('update `users` set `username`="' + username + '",`age`="' + age + '" where `id`="' + id + '"', (error, result) => {
            res.send(result)
        })
    }
}
module.exports = new Users();